package com.infocollect.project.grant.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.infocollect.framework.aspectj.lang.annotation.Log;
import com.infocollect.framework.aspectj.lang.enums.BusinessType;
import com.infocollect.project.grant.domain.GrFamilies;
import com.infocollect.project.grant.service.IGrFamiliesService;
import com.infocollect.framework.web.controller.BaseController;
import com.infocollect.framework.web.domain.AjaxResult;
import com.infocollect.common.utils.poi.ExcelUtil;

/**
 * 科类维护Controller
 * 
 * @author infocollect
 * @date 2022-05-18
 */
@RestController
@RequestMapping("/grant/grantfamilies")
public class GrFamiliesController extends BaseController
{
    @Autowired
    private IGrFamiliesService grFamiliesService;

    /**
     * 查询科类维护列表
     */
    @PreAuthorize("@ss.hasPermi('grant:grantfamilies:list')")
    @GetMapping("/list")
    public AjaxResult list(GrFamilies grFamilies)
    {
        List<GrFamilies> list = grFamiliesService.selectGrFamiliesList(grFamilies);
        return AjaxResult.success(list);
    }

    /**
     * 导出科类维护列表
     */
    @PreAuthorize("@ss.hasPermi('grant:grantfamilies:export')")
    @Log(title = "科类维护", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GrFamilies grFamilies)
    {
        List<GrFamilies> list = grFamiliesService.selectGrFamiliesList(grFamilies);
        ExcelUtil<GrFamilies> util = new ExcelUtil<GrFamilies>(GrFamilies.class);
        return util.exportExcel(list, "grantfamilies");
    }

    /**
     * 获取科类维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('grant:grantfamilies:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(grFamiliesService.selectGrFamiliesById(id));
    }

    /**
     * 新增科类维护
     */
    @PreAuthorize("@ss.hasPermi('grant:grantfamilies:add')")
    @Log(title = "科类维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrFamilies grFamilies)
    {
        return toAjax(grFamiliesService.insertGrFamilies(grFamilies));
    }

    /**
     * 修改科类维护
     */
    @PreAuthorize("@ss.hasPermi('grant:grantfamilies:edit')")
    @Log(title = "科类维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrFamilies grFamilies)
    {
        return toAjax(grFamiliesService.updateGrFamilies(grFamilies));
    }

    /**
     * 删除科类维护
     */
    @PreAuthorize("@ss.hasPermi('grant:grantfamilies:remove')")
    @Log(title = "科类维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(grFamiliesService.deleteGrFamiliesByIds(ids));
    }
/**
 * @author dongpj
 * @date 2022/5/21 15:47
 * @param []
 * @return com.infocollect.framework.web.domain.AjaxResult
 * @describe 科类翻译的列表，全量返回
 */
    @GetMapping("/getFamiliesFormatList")
    public AjaxResult getFamiliesFormatList(GrFamilies grFamilies){
        List<GrFamilies> list = grFamiliesService.selectGrFamiliesList(grFamilies);
        return  AjaxResult.success(list);
    }
}
